package pe.edu.unmsm.fisi.sisconteg.repository.dao.impl;

import org.hibernate.SessionFactory;
import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.stereotype.Repository;

import pe.edu.unmsm.fisi.sisconteg.domain.model.Alumno;
import pe.edu.unmsm.fisi.sisconteg.repository.dao.AlumnoDAO;

@Repository("alumnoDAO")
public class AlumnoDAOImpl implements AlumnoDAO {

	private SessionFactory sessionFactory;
	
	@Autowired
	public void setSessionFactory(SessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;
	}

	@Override
	public Alumno getAlumnoxCodigo(String codigoAlumno)
			throws DataAccessException {
		Alumno alumno = null;
		alumno = (Alumno) sessionFactory.getCurrentSession().createCriteria(Alumno.class).
				add(Restrictions.eq("codigoAlumno", codigoAlumno)).uniqueResult();
		
		return alumno;
	}

}
